/**
 * 公共计算方法
 */

import {
    Platform,
    Dimensions
} from 'react-native';

// iPhoneX,iPhoneXS
const X_WIDTH = 375;
const X_HEIGHT = 812;

//iPhoneXR,iPhoneXS Max
const Max_WIDTH = 414;
const Max_HEIGHT = 896;

// screen
const SCREEN_WIDTH = Dimensions.get('window').width;
const SCREEN_HEIGHT = Dimensions.get('window').height;

export default {
    contentLength:function (content){
        let len = 0;
        let reg = /[\u4e00-\u9fa5]/;
        for(let i = 0;i<content.length;i++){
            if(reg.test(content[i])){
                len += 2;
            }else{
                len++;
            }
        }
        return len;
    },

    sliceContent:function (content,len) {
        let tmpLength =0;
        let tmpContent = '';
        let reg = /[\u4e00-\u9fa5]/;
        for(let i = 0;i<content.length;i++){
            if(reg.test(content[i])){
                tmpLength += 2;
            }else{
                tmpLength++;
            }
            if(tmpLength > len){
                tmpContent = content.slice(0,i-1);
                break;
            }
        }
        return tmpContent;
    },

    isIphoneX:function(){
        return (
            Platform.OS === 'ios' &&
            (((SCREEN_HEIGHT === X_HEIGHT && SCREEN_WIDTH === X_WIDTH) ||
            (SCREEN_HEIGHT === X_WIDTH && SCREEN_WIDTH === X_HEIGHT)) ||
            ((SCREEN_HEIGHT === Max_HEIGHT && SCREEN_WIDTH === Max_WIDTH) ||
            (SCREEN_HEIGHT === Max_WIDTH && SCREEN_WIDTH === Max_HEIGHT)))
        )
    }
 }
